package com.sheepone.util.structure;

/**
 * @author Miss.杨
 * @description
 * @since 2024/5/4 - 10:48
 */
public abstract class IndexedContainer extends Container {
    public IndexedContainer() {
        super();
    }

    public IndexedContainer(int capacity) {
        super(capacity);
    }

    protected void checkIndex(int index) {
        if (!isEffectiveIndex(index)) {
            throw new IndexOutOfBoundsException("index " + index + " out of bounds size " + size);
        }
    }

    protected boolean isEffectiveIndex(int index) {
        if(isEmpty()){
            return false;
        }
        return index >= 0 && index < size;
    }
}
